package jjn.round1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jjn
 * @since 2022/8/27 23:52
 */
public class LeetCode169_MajorityElement {
    public int majorityElement(int[] nums) {
        if (nums == null) {
            return -1;
        }
        Map<Integer, Integer> map = new HashMap<>(16);
        for (int i : nums) {
            Integer count = map.getOrDefault(i, 0);
            count++;
            if (count > nums.length / 2) {
                return i;
            }
            map.put(i, count);
        }
        return -1;
    }
}
